<?php
	$where_cat = "";
	if(isset($_GET['var2']))
		$where_cat = " where titleurl = '".$_GET['var2']."' ";
	
	$re_cat = $db->select("select * from product_cat $where_cat  order by orderId asc, id asc limit 1 ");
	$tt_cat = $db->fetch($re_cat);
        
        $arr_cat = $tt_cat['id'];
        
        //lay category con 
        $re_cat2 = $db->select("select * from product_cat where parentid = '".$tt_cat['id']."'");
	$tt_cat2 = $db->fetch($re_cat2);
        
        //lay category chau
        if(!empty($tt_cat2)){
            $arr_cat .= ','.$tt_cat2['id'];
            
            $re_cat3 = $db->select("select * from product_cat where parentid = '".$tt_cat2['id']."'");
            $tt_cat3 = $db->fetch($re_cat3);
            if(!empty($tt_cat3)){
                $arr_cat .= ','.$tt_cat3['id'];
            }
            
        }
        
        
        $where_arr_cat = " where idcat IN ($arr_cat)";
     
?>
<div class="left-col">
	<div class="title fsize17"><?= $co_product['titlemenu'.$hg] ?></div>
	
	<ul class="pl-list">
		<?php
		$re_list = $db->select("select * from product_cat where level = 1 order by orderId asc");
		while($tt_list = $db->fetch($re_list))
		{
			if(($act=="product" || $act=="product-detail" ) && $tt_list['id'] == $tt_cat['id'])
				$subClass = "active";
			else 
				$subClass = "";
		?>
		<li class="<?= $subClass ?>">
                    <a href="<?=APPLICATION_URL?>product/<?=$tt_list['titleurl']?>.html"><?=$tt_list['title'.$hg]?></a>
                    
                    <ul>
                        <?php
                        $re_list2 = $db->select("select * from product_cat where level = 2 and parentid=".$tt_list['id']." order by orderId asc");
                        while($tt_list2 = $db->fetch($re_list2))
                        {
                                if(($act=="product" || $act=="product-detail" ) && $tt_list2['id'] == $tt_cat['id'])
                                        $subClass2 = "active";
                                else 
                                        $subClass2 = "";
                        ?>
                        <li class="<?= $subClass2 ?>">
                            <a href="<?=APPLICATION_URL?>product/<?=$tt_list2['titleurl']?>.html"><?=$tt_list2['title'.$hg]?></a>
                            <ul>
                                <?php
                                $re_list3 = $db->select("select * from product_cat where level = 3 and parentid=".$tt_list2['id']." order by orderId asc");
                                while($tt_list3 = $db->fetch($re_list3))
                                {
                                        if(($act=="product" || $act=="product-detail" ) && $tt_list3['id'] == $tt_cat['id'])
                                                $subClass3 = "active";
                                        else 
                                                $subClass3 = "";
                                ?>
                                <li class="<?= $subClass3 ?>">
                                    <a href="<?=APPLICATION_URL?>product/<?=$tt_list3['titleurl']?>.html"><?=$tt_list3['title'.$hg]?></a>
                                </li>
                                <?php } ?>
                                
                            </ul>
                        </li>
                        
                        <?php } ?>
                    </ul>
		</li>
		<?php
		}
		?>
		
	</ul>
</div>
<div class="right-col">
	<div class="title"><?=$tt_cat['title'.$hg]?></div>
        <?php if(!empty($tt_cat['image'])): ?>
        <img class="cat-image" src="<?=APPLICATION_URL?>product-img/<?=$tt_cat['image']?>">
        <?php endif; ?>
	<ul class="pro-items">
		<?php			
		$i = 0;					
		include_once "library/paging.cls.php";
		$paging=new paging();
		$curpg = $_GET['var3'];
		$curpg=(isset($curpg))?$curpg:1;	
		$gotopage  = APPLICATION_URL."product/".$tt_cat['titleurl'];					
		$perpage = 9;
		$pagecount = 10;				
		//$where_list = " where idcat = '".$tt_cat['id']."' ";
                $where_list = $where_arr_cat;
		$sql = "select * from product_item $where_list  ";
		
		$query = $db->select($sql);	
		$totalrows=$db->numrows($query);	
		$sql_list = "select * from product_item $where_list order by orderId asc, id asc limit ".(($curpg-1)*$perpage).", ".$perpage;	
		$qr_list = $db->select($sql_list);	
		$num_list = $db->numrows($qr_list);
		if ($num_list > 0) {					
			while($tt_list = $db->fetch($qr_list))
			{ 
				$i++;
				if(($i - 1)%3 == 1)
					$margin = 'class="pro-margin"';
				else
					$margin = "";
			?>
				<li <?= $margin; ?>>
					<div class="pro-item-ctn">
						<!--<a href="<?=APPLICATION_URL?>product-detail/<?=$tt_cat['titleurl']?>/<?=$tt_list['titleurl']?>.html"><img alt="" src="<?=APPLICATION_URL?>product-img/list/<?=$tt_list['image']?>"></a>-->
						<a href="<?=APPLICATION_URL?>product-detail/<?=$tt_list['titleurl']?>.html"><img alt="" src="<?=APPLICATION_URL?>product-img/list/<?=$tt_list['image']?>"></a>
                                                <!--<div class="name"><a href="<?=APPLICATION_URL?>product-detail/<?=$tt_cat['titleurl']?>/<?=$tt_list['titleurl']?>.html"><?=$tt_list['title'.$hg]?></a></div>-->
                                                <div class="name"><a href="<?=APPLICATION_URL?>product-detail/<?=$tt_list['titleurl']?>.html"><?=$tt_list['title'.$hg]?></a></div>
						<!--<div class="home-right-bg"><?= formatPrice($tt_list['price']); ?></div>-->
					</div>
				</li>
		<?php
			}
		}else{
                    
			if ($hg) { //Tiếng Việt
				echo 'Không có sản phẩm nào trong thể loại này';
			}else{
				echo 'No product in this category';
			}
		}
		?>
		
	</ul>
	<div class="clear"></div>
	<div class="paging"><?php echo $paging->pagenew($totalrows, $perpage, $pagecount, $curpg, $gotopage, "","titlepage");?></div>
</div>
